﻿// ------------------------------------------------------------------------
// 项目名称：Canroc.Net 
// 版权归属：Canroc（https://gitee.com/canroc）
//
// 许可证信息
// Canroc.Net项目主要遵循 Apache 许可证（版本 2.0）进行分发和使用。许可证位于源代码树根目录中的 LICENSE-APACHE 文件。
//
// 使用条款：
// 1.使用本项目应遵守相关法律法规和许可证的要求。
// 2.不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动。
// 3.任何基于本项目二次开发而产生的一切法律纠纷和责任，我们不承担任何责任
//
// 免责声明
// 对于因使用本代码而产生的任何直接、间接、偶然、特殊或后果性损害，我们不承担任何责任。
//
// 其他重要信息
// Canroc.Net 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。
// ------------------------------------------------------------------------

using Canroc.Net.RemoteHttp.WeChatPay.Enum;

namespace Canroc.Net.RemoteHttp.WeChatPay.Dto;

/// <summary>
///     微信支付-退款申请输出项
/// </summary>
public class WeChatPayApiRefundOutput
{
    /// <summary>
    ///     微信支付退款号
    /// </summary>
    [MaxLength(32)]
    [JsonPropertyName("refund_id")]
    public string RefundId { get; set; } = string.Empty;

    /// <summary>
    ///     商户退款单号
    /// </summary>
    [MaxLength(64)]
    [JsonPropertyName("out_refund_no")]
    public string OutRefundNo { get; set; } = string.Empty;

    /// <summary>
    ///     微信支付订单号
    /// </summary>
    [MaxLength(32)]
    [JsonPropertyName("transaction_id")]
    public string TransactionId { get; set; } = string.Empty;

    /// <summary>
    ///     商户订单号
    /// </summary>
    [MaxLength(32)]
    [JsonPropertyName("out_trade_no")]
    public string OutTradeNo { get; set; } = string.Empty;

    /// <summary>
    ///     退款渠道
    /// </summary>
    [JsonPropertyName("channel")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public WeChatPayRefundChannelEnum Channel { get; set; }

    /// <summary>
    ///     退款入账账户
    /// </summary>
    [MaxLength(64)]
    [JsonPropertyName("user_received_account")]
    public string UserReceivedAccount { get; set; } = string.Empty;

    /// <summary>
    ///     退款成功时间
    /// </summary>
    [JsonPropertyName("success_time")]
    public DateTime? SuccessTime { get; set; }

    /// <summary>
    ///     退款创建时间
    /// </summary>
    [JsonPropertyName("create_time")]
    public DateTime CreateTime { get; set; }

    /// <summary>
    ///     退款状态
    /// </summary>
    [JsonPropertyName("status")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public WeChatPayRefundStatusEnum Status { get; set; }

    /// <summary>
    ///     资金账户
    /// </summary>
    [JsonPropertyName("funds_account")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public WeChatPayRefundAmountFromAccountEnum? FundsAccount { get; set; }

    /// <summary>
    ///     金额信息
    /// </summary>
    [JsonPropertyName("amount")]
    public RefundAmount Amount { get; set; } = new();

    /// <summary>
    ///     优惠退款信息
    /// </summary>
    [JsonPropertyName("promotion_detail")]
    public List<RefundPromotionDetail>? PromotionDetail { get; set; }
}

/// <summary>
///     微信退款金额信息
/// </summary>
public class RefundAmount
{
    /// <summary>
    ///     订单金额
    /// </summary>
    [JsonPropertyName("total")]
    public int Total { get; set; }

    /// <summary>
    ///     退款金额
    /// </summary>
    [JsonPropertyName("refund")]
    public int Refund { get; set; }

    /// <summary>
    ///     退款出资账户及金额
    /// </summary>
    [JsonPropertyName("from")]
    public List<RefundAmountFrom>? From { get; set; }

    /// <summary>
    ///     用户支付金额
    /// </summary>
    [JsonPropertyName("payer_total")]
    public int PayerTotal { get; set; }

    /// <summary>
    ///     用户退款金额
    /// </summary>
    [JsonPropertyName("payer_refund")]
    public int PayerRefund { get; set; }

    /// <summary>
    ///     应结退款金额
    /// </summary>
    [JsonPropertyName("settlement_refund")]
    public int SettlementRefund { get; set; }

    /// <summary>
    ///     应结订单金额
    /// </summary>
    [JsonPropertyName("settlement_total")]
    public int SettlementTotal { get; set; }

    /// <summary>
    ///     优惠退款金额
    /// </summary>
    [JsonPropertyName("discount_refund")]
    public int DiscountRefund { get; set; }

    /// <summary>
    ///     退款币种
    /// </summary>
    [MaxLength(16)]
    [JsonPropertyName("currency")]
    public string Currency { get; set; } = string.Empty;

    /// <summary>
    ///     手续费退款金额
    /// </summary>
    [JsonPropertyName("refund_fee")]
    public int? RefundFee { get; set; }
}

/// <summary>
///     微信退款出资账户及金额
/// </summary>
public class RefundAmountFrom
{
    /// <summary>
    ///     出资账户类型
    /// </summary>
    [JsonPropertyName("account")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public WeChatPayRefundAmountFromAccountEnum Account { get; set; }

    /// <summary>
    ///     出资金额
    /// </summary>
    [JsonPropertyName("amount")]
    public int Amount { get; set; }
}

/// <summary>
///     优惠退款信息
/// </summary>
public class RefundPromotionDetail
{
    /// <summary>
    ///     券ID
    /// </summary>
    [MaxLength(32)]
    [JsonPropertyName("promotion_id")]
    public string PromotionId { get; set; } = string.Empty;

    /// <summary>
    ///     优惠范围
    /// </summary>
    [JsonPropertyName("scope")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public WeChatPayRefundPromotionDetailScopeEnum Scope { get; set; }

    /// <summary>
    ///     优惠类型
    /// </summary>
    [JsonPropertyName("type")]
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public WeChatPayRefundPromotionDetailTypeEnum Type { get; set; }

    /// <summary>
    ///     优惠券面额
    /// </summary>
    [JsonPropertyName("amount")]
    public int Amount { get; set; }

    /// <summary>
    ///     优惠退款金额
    /// </summary>
    [JsonPropertyName("refund_amount")]
    public int RefundAmount { get; set; }

    /// <summary>
    ///     商品列表
    /// </summary>
    [JsonPropertyName("goods_detail")]
    public List<RefundPromotionDetailGoodsDetail>? GoodsDetail { get; set; }
}

/// <summary>
///     优惠商品信息
/// </summary>
public class RefundPromotionDetailGoodsDetail
{
    /// <summary>
    ///     商户侧商品编码
    /// </summary>
    [MaxLength(32)]
    [JsonPropertyName("merchant_goods_id")]
    public string MerchantGoodsId { get; set; } = string.Empty;

    /// <summary>
    ///     微信侧商品编码
    /// </summary>
    [MaxLength(32)]
    [JsonPropertyName("wechatpay_goods_id")]
    public string? WechatpayGoodsId { get; set; }

    /// <summary>
    ///     商品名称
    /// </summary>
    [MaxLength(256)]
    [JsonPropertyName("goods_name")]
    public string? GoodsName { get; set; }

    /// <summary>
    ///     商品单价
    /// </summary>
    [JsonPropertyName("unit_price")]
    public int UnitPrice { get; set; }

    /// <summary>
    ///     商品退款金额
    /// </summary>
    [JsonPropertyName("refund_amount")]
    public int RefundAmount { get; set; }

    /// <summary>
    ///     商品退货数量
    /// </summary>
    [JsonPropertyName("refund_quantity")]
    public int RefundQuantity { get; set; }
}